
import java.lang.String;
import java.util.*;
        import java.util.regex.Pattern;
import java.util.Random;
public class usertest {
    public static void main(String[] args) {
        ArrayList<user>list = new ArrayList<>();
        // 初始化登录尝试次数映射
        Map<String, Integer> loginAttempts = new HashMap<>();
        // 显示用户操作界面
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("用户使用界面");
            System.out.println("请选择操作：1登录  2注册  3忘记密码   4修改密码");
            String choose = sc.nextLine();
            switch (choose) {
                case "1" -> login(list);
                case "2" -> register(list);
                case "3" -> forgetpassword(list);
                case "4" -> Changepassword(list);

                default -> System.out.println("没有这个选项");


            }
        }
    }
    // 登录函数
    public  static void login(ArrayList<user>list) {
        String rightusername="customer";
        String rightpassword="Password123@";
        for (int i = 0; i < 5; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入用户名");
            String username = sc.next();
            System.out.println("请输入用户密码");
            String password = sc.next();
            if(username.equals(rightusername)&&password.equals(rightpassword)) {
                System.out.println("登陆成功");
                break;
            }else{
                System.out.println("用户登录失败，还有" + (4 - i) + "次机会");
            }

        }
    }
    // 修改密码函数
    private static void Changepassword (ArrayList < user > list) {
        String rightusername="customer";
        String rightpassword="Password123@";
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名");
        String newname=sc.next();
        System.out.println("请输入原来的密码");
        String newpassword=sc.next();
        System.out.println("密码修改成功，"+"新密码为："+newpassword+"1");

    }
    // 忘记密码函数
    private static void forgetpassword (ArrayList < user > list) {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要重置的的用户名");
        String resetUsername =sc.next();
        System.out.println("请输入该用户的邮箱以重置密码: ");
        String resetEmail =sc.next();
        Random rand = new Random();
        String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        System.out.println("生成的随机密码为"+rand);
    }
    // 注册函数
    private static void register (ArrayList < user > list) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入用户名");
        String username = sc.nextLine();
        System.out.print("请输入密码: ");
        String password = sc.nextLine();
        if (username.length() < 5) {
            System.out.println("用户名长度必须不少于5个字符");
            return; // 如果用户名长度不符合要求，直接返回
        }

        // 密码正则表达式验证
        // 密码需要包含大小写字母、数字和标点符号，且长度大于8个字符
        String passwordPattern = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@$!%*?&])[A-Za-z\\d@$!%*?&]{8,}$";
        if (!Pattern.matches(passwordPattern, password)) {
            System.out.println("注册失败,密码长度必须大于8个字符，且必须包含大小写字母、数字和标点符号");
            return; // 如果密码不符合要求，直接返回
        } else {

            // 如果都通过验证，则注册成功
            System.out.println("注册成功！");

        }

    }



}